'''
   Weibo account's methods
'''
import MySQLdb
import types
from MySqlDBHandle import MySqlDBHandle

class WeiboAcc():
    mSQLInsertStatement = "INSERT INTO WeiboAcc (id, screen_name, name, followers_count, LAST_UPDATE_TIMESTAMP) VALUES %s ON DUPLICATE KEY UPDATE LAST_UPDATE_TIMESTAMP = current_timestamp;"
    #mSQLQueryStatement = "SELECT * FROM WeiboAcc WHERE id = %s;"
    mSQLValueStatement = "(%s, '%s', '%s', %s, current_timestamp),"
      
    def __init__(self, iParams):
        self.mParams = iParams

    def _sendToDB(self):
        assert(type(self.mParams) == types.ListType)
        lValueStatement = ""
        for lWeiboAcc in self.mParams:
            lValueStatement += (self.mSQLValueStatement % (lWeiboAcc['id'], \
    		    lWeiboAcc['screen_name'], lWeiboAcc['name'], lWeiboAcc['followers_count']))

        lSQLStatement = self.mSQLInsertStatement % lValueStatement[:len(lValueStatement) - 1]
        #print lSQLStatement
        try:
            MySqlDBHandle.execSqlStatement(lSQLStatement)
        except Exception, e:
            print "Error in WeiboAcc.py sendToDB fuction"
            #Tdd some process if necessary

    def process(self):
        if type(self.mParams) == types.ListType and len(self.mParams) > 0:
            self._sendToDB()

